package engine

import (
	"log"
)

type SimpleEngine struct {}

func (s SimpleEngine) Run(seeds ...Request) {
	var requests []Request		// 请求队列
	for _, r := range seeds {
		requests = append(requests, r)
	}

	for len(requests) > 0 {
		r := requests[0]
		requests = requests[1:]

		parseResult, err := worker(r)
		if err != nil {
			continue
		}

		// 3. 处理网页解析结果
		for _, item := range parseResult.Items {
			log.Printf("Got item %v", item)
		}

		requests = append(requests, parseResult.Requests...)	// 将网页中需要再次Fetcher的url加入请求队列
	}
}
